package com.cover.fti.play;

import java.util.LinkedList;

import org.anddev.andengine.entity.primitive.Rectangle;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;


public class Tower extends AnimatedSprite{

	private Boolean move;
	private Boolean readyToFire;
	private Boolean remove;
	private String tipe;
	private int damage;
	private float speedBullet;
	private long price;
	private Rectangle backTower;
	private TiledTextureRegion mTowerTiledTextureRegion;
	private TOWER mTOWER;
	private int index;
	//private boolean touch = false;
	//private LinkedList<Tower> mTowerLL;

	public Tower(float pX, float pY, float pTileWidth, float pTileHeight,
			TiledTextureRegion pTiledTextureRegion, TOWER tower) {
		super(pX, pY, pTileWidth, pTileHeight, pTiledTextureRegion);
		// TODO Auto-generated constructor stub
		this.mTowerTiledTextureRegion = pTiledTextureRegion;
		mTOWER = tower;
		setTower(tower);
		move = true;
		readyToFire = false;
		remove = false;
		backTower = new Rectangle(0, 0, this.getWidth(), this.getHeight());
		backTower.setColor(0, 0, 0, 0);
		attachChild(backTower);
		
	}
	
	public int getIndex(){
		return index;
	}
	
	public void setLinkedListTower(LinkedList<Tower> pTowerLL){
		//mTowerLL = pTowerLL;
	}
	

	public void setTower(TOWER tower) {
		if(tower == TOWER.NORMAL){
			index = 0;
			price = 100;
			tipe = "normal";
		} else if(tower == TOWER.HEAVY){
			index = 1;
			price = 200;
			tipe = "heavy";
		} else if(tower == TOWER.DESTRUCTION){
			index = 2;
			price = 300;
			tipe = "destruction";
		}
	}

	public TOWER getTipeTower(){
		return mTOWER;
	}
	
	public float getSpeedBullet() {
		return speedBullet;
	}

	public void setPrice(long price) {
		this.price = price;
	}

	public long getPrice() {
		return price;
	}

	public void setRemove(boolean remove) {
		this.remove = remove;
	}

	public boolean getRemove() {
		return this.remove;
	}

	public void setBackColor(float pRed, float pGreen, float pBlue, float pAlfa) {
		backTower.setColor(pRed, pGreen, pBlue, pAlfa);
	}

	public void setReadyToFire(Boolean ready) {
		readyToFire = ready;
	}

	public Boolean getReadyToFire() {
		return readyToFire;
	}

	public void setMove(Boolean move) {
		this.move = move;
	}

	public Boolean getMove() {
		return this.move;
	}

	public void setString(String tipe) {
		this.tipe = tipe;
	}

	public String getTipe() {
		return this.tipe;
	}

	public void setDamage(int damage) {
		this.damage = damage;
	}

	public int getDamage() {
		return damage;
	}

	public TiledTextureRegion getTowerTiledTextureRegion() {
		return this.mTowerTiledTextureRegion;
	}
	
	public enum TOWER{
		NONE,
		NORMAL,
		HEAVY,
		DESTRUCTION;
	}
	
//	@Override
//	public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
//			ITouchArea pTouchArea, float pTouchAreaLocalX,
//			float pTouchAreaLocalY) {
//		this.setPosition(pTouchAreaLocalX, pTouchAreaLocalY);
		// TODO Auto-generated method stub
//		switch(pSceneTouchEvent.getAction()){
//		case TouchEvent.ACTION_DOWN:
//			touch = true;
//			return true;
//		case TouchEvent.ACTION_MOVE:
//			touch = true;
//			return true;
//		case TouchEvent.ACTION_UP:
//			touch = false;
//			return true;
//		}
//		boolean canCreateTowerHere = false;
//		boolean isCollideWithOtherTower = false;
//		boolean isOverArea = false;
//
//		if(pSceneTouchEvent.isActionDown()){
//		}
//		
//		if (this.getMove()) {
//			setPosition(pSceneTouchEvent.getX()
//					- (this.getWidth() / 2),
//					pSceneTouchEvent.getY()
//							- (this.getHeight() / 2));
//			if (mTowerLL.size() > 1) {
//				for (int i = 0; i < mTowerLL.size() - 1; i++) {
//					Tower tower = mTowerLL.get(i);
//					if (this.collidesWith(tower)) {
//						isCollideWithOtherTower = true;
//						break;
//					} else {
//						isCollideWithOtherTower = false;
//					}
//				}
//			} else {
//				isCollideWithOtherTower = false;
//			}
//
//			if (this.getX() < PlayGameActivity.WALL_TOWER - this.getWidth() / 2
//					&& this.getY() < PlayGameActivity.CAMERA_HEIGHT - PlayGameActivity.MENU_TOWER
//							- this.getHeight() / 2
//					&& this.getY() > PlayGameActivity.STATUS_PLAYER
//							+ this.getHeight() / 2) {
//				isOverArea = false;
//			} else {
//				isOverArea = true;
//			}
//
//			if (!isCollideWithOtherTower && !isOverArea) {
//				setBackColor(0f, 1f, 0f, 0.5f);
//				canCreateTowerHere = true;
//			} else {
//				setBackColor(1f, 0, 0, 0.5f);
//			}
//
//		}
//		if (pSceneTouchEvent.isActionUp()) {
//			if (canCreateTowerHere) {
////				this.setMove(false);
//				this.setReadyToFire(true);
//				this.setRemove(false);
//				PlayGameActivity.mMainScene.unregisterTouchArea(this);
//				setBackColor(1, 1, 1, 0);
//				PlayGameActivity.minusGold(price);
//			} else {
//				this.setRemove(true);
//			}
//		}
//		PlayGameActivity.mMainScene.registerTouchArea(this);
//		return true;
//	}

}
